home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / DataField.java < prev    next >
Text File  |  2002-07-03  |  15KB  |  497 lines

  1.  
  2. /**
  3.  * title:     DataField class (DataField.java)<p>
  4.  * description:  Specialized class for definition of the JNI method<p>
  5.  * Copyright (C) 1996-2001 Keio University <p>
  6.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  7.  *               GNU General Public Licence <p>
  8.  * Division:     Mitsui Knowledge Industry Co. Ltd. Bioscience division <p>
  9.  * Version :     $Id: DataField.java,v 1.7 2002/05/13 00:23:04 ota Exp $ <p>
  10.  */
  11.  
  12.  
  13. package ecell;
  14. import java.util.StringTokenizer;
  15. import javax.swing.*;
  16. import java.awt.event.*;
  17.  
  18.  
  19. /**
  20.  * Specialized class for definition of the JNI method 
  21.  * @author         XD.Zheng
  22.  * @version  1.0
  23.  * @since  JDK1.2.2
  24.  */
  25.  
  26. public  class DataField {
  27.  
  28.     /**
  29.      * Instance of controll panel
  30.      */
  31.     MainWindow win;
  32.  
  33.     /**
  34.      * Constructor
  35.      * @param window    Instance of controll panel
  36.      */
  37.     public DataField(MainWindow window){
  38.         this.win = window;
  39.     }
  40.  
  41.     /**
  42.      * Prepare the method for generating the Substance window from JNI.
  43.      * @param code      Window Number
  44.      * @param str1      Substance EntryName
  45.      * @param str2      Substance Name
  46.      * @return void
  47.      */
  48.     private void creatSubstance(int code,String str1,String str2){
  49.         Substance substance = new Substance(code,str1,str2,win);
  50.         //win.vSubstance.addElement(substance);
  51.  
  52.         substance.setVisible(true);
  53.         //substance.setLocation(150,100);
  54.     }
  55.  
  56.     /**
  57.      * Prepare the method for generating the Reactor window from JNI. 
  58.      * @param code      Window Number
  59.      * @param str1      Reactor EntryName
  60.      * @param str2      Reactor Name
  61.      * @param str3      Reactor className
  62.      * @return void
  63.      */
  64.     private void creatReactor(int code,String str1,String str2,String str3){
  65.         Reactor reactor = new Reactor(code,str1,str2,str3,win);
  66.         //win.vReactor.addElement(reactor);
  67.         
  68.         reactor.setVisible(true);
  69.         //reactor.setLocation(150,100);
  70.     }
  71.  
  72.     /**
  73.      * Prepare method for generating the Tracer window from JNI.
  74.      * @param list1         EntryName
  75.      * @param list2         Name
  76.      * @param list3         ClassName
  77.      * @param objCodes      SubstanceNumber
  78.      * @param objTypes      SubstanceType
  79.      * @return void
  80.      */
  81.     private int creatTracer(String list1,String list2,String list3,int[] objCodes,int[] objTypes ){
  82.         
  83.         StringTokenizer st = new StringTokenizer(list1,"\n");
  84.         StringTokenizer st2 = new StringTokenizer(list2,"\n");
  85.         StringTokenizer st3 = new StringTokenizer(list3,"\n");
  86.         int count = st.countTokens();
  87.         String[] entryName=new String[count];
  88.         String[] name= new String[count] ;
  89.         String[] cname= new String[count];
  90.         for(int i=0;i<count;i++){
  91.             entryName[i]=st.nextToken();
  92.             name[i]=st2.nextToken();
  93.             cname[i]=st3.nextToken();
  94.         }
  95.         Tracer tracer = new Tracer(win,win.tracerNumber);
  96.         int no=win.tracerNumber;
  97.         win.tracerNumber++;
  98.         //win.vTracer.addElement(tracer);
  99.  
  100.         tracer.setCheckBox(entryName,name,cname,objCodes,objTypes );
  101.         tracer.setVisible(true);
  102.         //tracer.setLocation(150,100);
  103.         tracer.dispatchEvent( new ComponentEvent( tracer, ComponentEvent.COMPONENT_RESIZED ) );
  104.         return no;
  105.     }
  106.  
  107.     /**
  108.      * Prepare the method for closing the Substance window from JNI.
  109.      * @param code      Window Number
  110.      * @return void
  111.      */
  112. /**
  113.     void closeSubstance(int code){
  114.         for(int i=0;i<win.vSubstance.size();i++){
  115.             Substance ss =(Substance) win.vSubstance.elementAt(i);
  116.             if (ss.subCode==code){
  117.                 ss.exit_actionPerformed();
  118.                 i--;
  119.             }
  120.         }
  121.     }
  122. **/
  123.  
  124.     /**
  125.      * Prepare the method for closing the Reactor window from JNI.
  126.      * @param code       Window Number 
  127.      * @return void
  128.      */
  129. /**
  130.     private void closeReactor(int code){
  131.         for(int i=0;i<win.vReactor.size();i++){
  132.             Reactor rt=(Reactor) win.vReactor.elementAt(i);
  133.             if(rt.rctCode==code){
  134.                 rt.exit_actionPerformed();
  135.                 i--;
  136.             }
  137.         }
  138.     }
  139. **/
  140.  
  141.     /**
  142.      * Prepare the method for closing the Tracer window from JNI.
  143.      * @param code       Window Number
  144.      * @return void
  145.      */
  146. /**
  147.     private void closeTracer(int code){
  148.         for(int i=0;i<win.vTracer.size();i++){
  149.             Tracer tc=(Tracer)win.vTracer.elementAt(i);
  150.             if(tc.tracerNumber==code){
  151.                 win.vTracer.remove(i);
  152.                 tc.exitTracer();
  153.             }
  154.         }
  155.     }
  156. **/
  157.  
  158.     /**
  159.      * Display a message from JNI on the UI window. 
  160.      * @param message    Displayed message 
  161.      * @return void
  162.      */
  163.     protected void showMessage1(String message){
  164.         String title="Message Dialog";
  165.         JOptionPane.showMessageDialog(null,message,title,JOptionPane.INFORMATION_MESSAGE);
  166.     }
  167.  
  168.     /**
  169.      * Display a message from JNI on the UI window. 
  170.      * @param message       Displayed message
  171.      * @param button1       Button1   
  172.      * @param button2       Button2 
  173.      * @return              <code>1</code> Push button1
  174.      *                      <code>2</code> Push button2
  175.      */
  176.     private int showMessage2(String message, String button1,String button2){
  177.         String title="Message Dialog";
  178.         Object[] options=new Object[2];
  179.         options[0]=button1;
  180.         options[1]=button2;
  181.         int ret=JOptionPane.showOptionDialog(null,message,title,0,
  182.             JOptionPane.ERROR_MESSAGE,null,options,options[0]);
  183.         return ret+1;
  184.     }
  185.  
  186.     /**
  187.      * Display a message from JNI on the UI message window. 
  188.      * @param message    Displayed message 
  189.      * @return void
  190.      */
  191.     protected void showMessage3(String message)
  192.     {
  193.         win.messageWindow.setMessage( message, false );
  194.     }
  195.  
  196.     /**
  197.      * Thread is started by JNI.
  198.      * @return void
  199.      */
  200.     protected void startThread(){
  201.         
  202.         win.startAction();
  203.     }
  204.  
  205.     /**
  206.      * Thread is stopped by JNI.
  207.      * @return void
  208.      */
  209.     protected void stopThread(){
  210.         win.stopAction();
  211.         win.setStopActionFlag( true );
  212.     }
  213.  
  214.     /**
  215.      * Inform the end of reading UIScript from JNI. 
  216.      * @return  void
  217.      */
  218.     private void setScriptFlag(){
  219.         win.setScriptFlag();
  220.     }
  221.  
  222.  
  223.     /**
  224.      * Natice method :Get tracer data  
  225.      *  @param count        The number of times 
  226.      *  @param code         Substance Number
  227.      *  @param data         Ouptput Data Arrangement data[0]= time, data[1]=Data
  228.      *  @return void
  229.      */
  230.     public   native void getTracerData(int count, int code,double[] data ) throws Exception;
  231.  
  232.     /**
  233.      * Native method
  234.      * Send the change to JNI when the "+" or "-" button on Substance window is pushed.
  235.      * @param  number     Window Number
  236.      * @param  a   1 "+" ,-1 "-".
  237.      * @return void
  238.      */
  239.     public   native void setJniChange(int number,int a) throws Exception;
  240.  
  241.     /**
  242.      * Native method : Get data from the Substance window.
  243.      * @param count     The number of steps 
  244.      * @param code      Window Number
  245.      * @param data2     Ouptput Data Array
  246.      * @return void
  247.      */
  248.     public   native void getSubstanceData(int count,int code, double[] data2) throws Exception;
  249.  
  250.     /**
  251.      *  Native method : Get data from the Reactor window.
  252.      * @return void 
  253.      * @param count     The number of steps 
  254.      * @param data      Ouptput Data Array 
  255.      * @return void
  256.      */
  257.     public   native double getReactorData(int count,int code) throws Exception;
  258.  
  259.     /**
  260.      * Native Method : Inform JNI when the button on the Tracer window is pushed.
  261.      * @return (Nothing)
  262.      * @param  t        Window Number
  263.      * @param  flag     -1 Close button : 1 Add button : 0 Open
  264.      * @return void
  265.      */
  266.     public   native void setTracerState(int t,int flag) throws Exception;
  267.  
  268.     /**
  269.      * Native Method :Inform JNI when the button on the Substance window is pushed. 
  270.      * @param  s       Window Number 
  271.      * @param  flag     -1 Close button 
  272.      * @return void
  273.      */
  274.     public   native void setSubstanceState(int s,int flag) throws Exception;
  275.  
  276.     /**
  277.      * Native Method :Inform JNI of the condition of FixCheckBox on the Substance window.
  278.      * @param  s        Window Number 
  279.      * @param  bl       State of Fix : true  select : false  not select
  280.      * @return void
  281.      */
  282.     public   native void setSubstanceFix(int s,boolean bl) throws Exception;
  283.  
  284.     /**
  285.      * Native Method : Transfer the value, contained in the textfield on the Substance window, to JNI
  286.         * @return (Nothing)
  287.      * @param s         Window Number
  288.      * @param type      Classification of TextField : 0 quantity 1 concentration
  289.      * @param data      Input data 
  290.      * @return void
  291.      */
  292.     public   native void setSubstanceText(int s,int type,double data) throws Exception;
  293.  
  294.     /**
  295.      * Native Method : Inform JNI when the button on the Reactor window is pushed.
  296.      * @param  s       Window Number 
  297.      * @param  flag     -1 Close button
  298.      * @return void
  299.      */
  300.     public   native void setReactorState(int s,int flag) throws Exception;
  301.  
  302.     /**
  303.      * Native Method 
  304.      * Get the name list of Substrate, Product, Catalyst, and Effector on the Reactor window. 
  305.      * There can be some items, delimited by space characters, in a string. 
  306.      * @param s         Window number
  307.      * @return          The name list of Substrate, Product, Catalyst, Effector
  308.      */
  309.     public   native String[] getReactorSpce(int s) throws Exception;
  310.  
  311.     /**
  312.      * Native method : Get the Param Name from the Reactor window.
  313.      * @param s      Window Number
  314.         * @return        Param Name
  315.       */
  316.     public   native String[] getReactorParamName(int s) throws Exception;
  317.  
  318.     /**
  319.      * Native method : Get the Param Value from the Reactor window. 
  320.      * @param s        Window Number
  321.      * @param values   Ouptput  Data arrangement
  322.      * @return  void
  323.      */
  324.     public   native void getReactorParamValue(int s,double[] values) throws Exception;
  325.  
  326.     /**
  327.      * Native method : Set Preference 
  328.      * @param step     step
  329.      * @param update   update
  330.      * @return void
  331.      *Correspondent relation int cp_preference(Float *s,int *u) (6.1.1)
  332.      */
  333.     public   native void setPreference(double step, int update) throws Exception;
  334.  
  335.     /**
  336.      * Native method : Process Rule file (Load Rule).
  337.      * @param  filename     FileName
  338.      * @return void
  339.      */
  340.     public   native int setRuleFile(String filename) throws Exception;
  341.  
  342.     /**
  343.      * Native method : Process Script file (Load Script).
  344.      * @param  filename     FileName 
  345.      * @return void
  346.      */
  347.     public   native int setScriptFile(String filename) throws Exception;
  348.  
  349.     /**
  350.      * Native method : Process CellState file (Load Cell State)
  351.      * @param  filename      FileName 
  352.      * @return void
  353.      */
  354.     public   native void setCellStateFile(String filename) throws Exception;
  355.  
  356.     /**
  357.      * Get the progress time of simulation from CORE.
  358.      * @return  double  Progress time in second within simulation
  359.      */
  360.     public native double getTime();
  361.  
  362.     /**
  363.      * Prepare the method for calling a Java method at the JNI side. 
  364.      * @return void
  365.      */
  366.     public native void setWindows() throws Exception;
  367.  
  368.     /**
  369.      * Prepare the method for calling a Java method at the JNI side. 
  370.      * @return void
  371.      */
  372.     public native void closeWindows() throws Exception;
  373.  
  374.     /**
  375.      * Get contents of the tree structure of EntrySelector. 
  376.      * @return   Data array
  377.      */
  378.     public native String getEntryData() throws Exception;
  379.  
  380.     /**
  381.      * Return the item, selected at the EntrySelector window, to JNI. 
  382.         * @param  windowNumber     Tracer Number -1 Substance, Reactor  >=0 
  383.      * @param  UiType           Window type 1 Substance 2 Reactor
  384.      * @param  windowId         Returned data array The last element is 0. 
  385.      */
  386.     public native void setEntrySelected(int windowNumber,int UiType, int windowId ) throws Exception;
  387.  
  388.     /**
  389.      * When a button of MainWindow is pushed, CORE reacts with the corresponding behavior. 
  390.      * @param type      Window button 0 Start 1 Stop 2 Step
  391.         * @return void
  392.      */
  393.     public native int setMainWindowState(int type);
  394.  
  395.     /**
  396.      * Pass Param to CORE when the software starts up. 
  397.      * @param arg Param
  398.      * @return  <code>1</code> Open the rule file. 
  399.      *          <code>0</code> Don't open the rule file.   
  400.      */
  401.     public native int setMainWindowsArg(String arg) ;
  402.  
  403.     /**
  404.      * Get the Preference Step value from CORE. 
  405.      * @return   Step  
  406.      */
  407.     public native  double getPreferenceStep();
  408.  
  409.     /**
  410.      * Get the Preference Update value from CORE. 
  411.      * @return Update  
  412.      */
  413.     public native int getPreferenceUpdate();
  414.  
  415.  
  416.     /**
  417.      * Get the Number of Substance Data from CORE. 
  418.      * @param objCode       Substance code
  419.      * @return  Number of Substance Data  
  420.      */
  421.     public native int getTracerDataNumber(int objCode);
  422.  
  423.     /**
  424.      * Get the Substance Data from CORE. 
  425.      * @param objCode  Substance code
  426.      * @param times    Time data
  427.      * @param datas    Data
  428.      * @return void      
  429.      */
  430.     public native void getAllTracerData(int objCode,double[] times,double[] datas);
  431.  
  432.     /**
  433.      * Native method : Process CellState file (Save Cell State). 
  434.      * @param  filename     File name
  435.      * @return void
  436.      */
  437.     public   native void saveCellStateFile(String filename) throws Exception;
  438.  
  439.  
  440.     /**
  441.      * Save Tracer window. 
  442.      * @param  Tracer  Window Number
  443.      * return  void
  444.      */
  445.     public   native void saveTracer(int objNumber) ;
  446.  
  447.  
  448. /********************************** for ecell2.2 **********************************/
  449.  
  450.     public native int calc( int steps, double time_to_stop );
  451.  
  452.     public native int updateInterface();
  453.  
  454.     public native int loadCs( String if_name );
  455.  
  456.     public native int saveCs( String if_name );
  457.  
  458.     public native int loadRule( String if_name );
  459.  
  460.     public native void saveScriptFileName( String if_name );
  461.  
  462.     public native void releaseReactor();
  463.  
  464.     public native void rescue();
  465.  
  466.     public native boolean ready();
  467.  
  468.     public native void setDelta( double dt, int opt );
  469.  
  470.     public native double getDelta();
  471.  
  472.     public native void setTime( double tm );
  473.  
  474.     public native int initCore( int arg_c, String str );
  475.  
  476.     public native void osifAddPath( String if_name );
  477.  
  478.     public native int vmDir( String if_path, int priority );
  479.  
  480.     public native int makeInterface( String if_type );
  481.  
  482.     public native int messageInterface( int i_handle, String if_param );
  483.  
  484.     public native int initializeInterface( int i_handle );
  485.  
  486.     public native int setDefaultAccumulator( String if_param );
  487.  
  488.     public static native boolean loadReactorDlls( int count, String dlls );
  489.     
  490.     public static native String getCoreVersion();
  491.     
  492.     public static native void getInitValues( int e_no, double[] data );
  493.  
  494. }
  495.  
  496.  
  497.